import user from '@/api/user'
export default{
    methods:{
        onAdd(){

            const userInfo = this.currentNode?{ssbm:this.currentNode.data.bmbh}:{};
            this.$refs.form.show(userInfo)
            .then((action)=>{
                if( action === 'ok'){
                    this.loadUsers();
                }
            });
        },
        onEdit(row){
            this.$refs.form.show(row)
            .then((action)=>{
                if( action === 'ok'){
                    this.loadUsers();
                }
            });
        },
        onDelete(row){
            this.$confirm('是否删除该用户？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                closeOnClickModal:false
            }).then((action) => {
                this.deleteUser(row);
            }).catch((action) => {
            });
        },
        onResetPassword(row){
            this.$confirm('是否重置该用户密码？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                closeOnClickModal:false
            }).then((action) => {
                this.resetUserPassword(row);
            }).catch((action) => {

            });
        },
        deleteUser(row){
            const ids = []
            ids.push(row.yhbh)
            user.delUser(ids)
            .then(response => {
                const { data } = response;
                if(data.error_code == 0){
                    this.loadUsers();
                    this.showInfo("操作成功！");
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
                this.showError("操作失败！");
            });
        },
        resetUserPassword(row){
            user.resetPassword({
                yhbh:row.yhbh
            })
            .then(response => {
                const { data } = response;
                if(data.error_code == 0){
                    this.showInfo("操作成功！");
                }else{
                    this.showError("操作失败！");
                }
                //this.reloadUserList();
            }).catch(error => {
                this.showError("操作失败！");
            });
        },
        onAddRole(row){

        },
        loadUsers(){
            //console.log(this.queryData)
            this.loading = true;
            user.queryUser(this.queryData)
            .then(response => {
                this.loading = false;
                const { data } = response;
                if( data.error_code == 0 ){
                    
                    this.users = data.list;
                    this.totalCount = data.totalCount;
                }else{
                    this.showError("操作失败！");
                }
            }).catch(error => {
                this.loading = false;
            });
        },
    }
}